<template>
  <div class="aside_container">
    <el-menu
      router
      unique-opened
      :collapse="isCollapse"
      :collapse-transition="false"
      :default-active="activePath"
      active-text-color="#FFE153"
      background-color="#bebebe"
      text-color="#000000"
    >
      <div class="toggle-button" @click="changeIsCollapse">
        <i :class="iconClass"></i>{{ menuBtnText }}
      </div>
      <el-submenu :index="item.id + ''" v-for="item in menuList" :key="item.id">
        <template slot="title">
          <i :class="item.menuIconClass"></i>
          <span>{{ item.menuName }}</span>
        </template>
        <el-menu-item-group>
          <el-menu-item
            :index="'/' + child.path"
            v-for="child in item.childs"
            :key="child.id"
            @click="saveActivePath('/' + child.path)"
          >
            {{ child.menuName }}
          </el-menu-item>
        </el-menu-item-group>
      </el-submenu>
    </el-menu>
  </div>
</template>

<script>
export default {
  props: {
    isCollapse: Boolean,
  },
  data() {
    return {
      iconClass: "el-icon-s-unfold",
      menuBtnText: "菜单目录",
      activePath: "",
      menuList: [
        {
          id: "1",
          menuName: "系统管理",
          menuIconClass: "s",
          path: "",
          childs: [
            {
              id: "2",
              menuName: "用户管理",
              menuIconClass: "",
              path: "user/userinfo",
            },
            {
              id: "3",
              menuName: "个人信息管理",
              menuIconClass: "",
              path: "user/userinfo1",
            },
          ],
        },
        {
          id: "4",
          menuName: "系统管理",
          menuIconClass: "s",
          path: "",
          childs: [
            {
              id: "5",
              menuName: "用户管理",
              menuIconClass: "",
              path: "user/userinfo2",
            },
            {
              id: "6",
              menuName: "个人信息管理",
              menuIconClass: "",
              path: "user/userinfo3",
            },
          ],
        },
      ],
    };
  },
  created() {
    this.activePath = window.sessionStorage.getItem("activePath");
  },
  methods: {
    changeIsCollapse() {
      if (!this.isCollapse) {
        this.iconClass = "el-icon-s-unfold";
        this.menuBtnText = "";
      } else {
        this.iconClass = "el-icon-s-fold";
        this.menuBtnText = "菜单目录";
      }
      console.info(this.isCollapse);
      this.$emit("changeIsCollapse");
    },
    saveActivePath(path) {
      window.sessionStorage.setItem("activePath", path);
    },
  },
};
</script>

<style scoped>
.aside_container {
  width: 100%;
  height: 100%;
  color: #000000;
}
.menuBtn {
  width: 100%;
  display: flex;
  align-items: flex-start;
}
.menuBtn li {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: flex-start;
}
.toggle-button {
  background-color: #bebebe;
  font-size: 14px;
  line-height: 50px;
  text-align: center;
  letter-spacing: 0.2em;
  cursor: pointer;
}
.el-menu {
  border: none;
  height: 100%;
}
</style>
